<include file="Public:title_top"/>

<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<title>小程序后台资源管理系统</title>
<link rel="shortcut icon" type="images/x-icon" href="__ROOT__/Public/Home/ico/ico.png">
<meta name="description" content="">
<meta name="author" content="">
<include file="Public:title_dn"/>

<style>
    .juli {
        margin-top: 20px;;
    }

    .table {
        width: 20%;
        margin-left: auto;
        margin-right: auto;
    }
</style>
</head>
<body>
<!--添加客户信息-->
<button class="btn btn-lg btn-info btn-default btn-block" onclick="reback()">返回</button>
<form action="{:U('uploads')}" method="post" enctype="multipart/form-data" class="form">
    <!--file定义输入字段和 "浏览"按钮，供文件上传。-->
    <div>
        <table class="table">
            <tr>
                <td>
                    <div class="input-prepend">
                        <span class="add-on btn btn-info btn-xs">商品图片：（种类图片）</span>
                        <input type="file" style="display: inline-block;" id="file"
                               class="span2 btn btn-default btn-xs juli"
                               name="file[]"
                               multiple="multiple"/>
                    </div>

                </td>
            </tr>
            <tr>
                <td>
                    <div class="input-prepend">
                        <span class="add-on btn btn-info btn-xs">商品类别：</span>
                        <select class="span2 btn btn-default btn-xs" name="type" id="select">
                            <option value="0">----请选择----</option>
                            <foreach name="type" item="v" key="k">
                                <option value="{$type[$k]['id']}">{$type[$k]['typename']}</option>
                            </foreach>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="input-prepend">
                        <span class="add-on btn btn-info btn-xs">商品描述</span>
                        <input type="text" name="title_m" id="title_m"/>
                        <span class="add-on btn btn-info btn-xs">商品数量</span>
                        <input type="text" name="num_m" id="num_m"/>
                        <span class="add-on btn btn-info btn-xs">商品价格</span>
                        <input type="text" name="price_m" id="price_m"/>
                    </div>
                </td>
            </tr>
            <tr id="add0">
                <td>
                    <div class="input-prepend">
                        <span class="add-on btn btn-info btn-xs">方案添加：</span>
                        <button type="button" class="btn btn-default btn-lg" onclick="add()"
                        >+
                        </button>
                    </div>
                    <div class="input-prepend juli">
                        <span class="add-on btn btn-info btn-xs">方案：</span>
                        <input type="text" name="attribute[]" value="" class="span2 btn btn-default btn-xs taocan"/>
                    </div>
                    <div class="input-prepend juli">
                        <span class="add-on btn btn-info btn-xs">方案图片</span>
                        <input type="file" style="display: inline-block;" id="fa_img"
                               class="span2 btn btn-default btn-xs juli"
                               name="fa_img[0][]"
                               multiple="multiple"/>
                    </div>
                    <!--TODO:价格小数-->
                    <div class="input-prepend juli">
                        <span class="add-on btn btn-info btn-xs">价格(进价)：</span>
                        <input type="number" name="price[]" value="" class="span2 btn btn-default btn-xs money"/>
                    </div>
                    <div class="input-prepend juli">
                        <span class="add-on btn btn-info btn-xs">上架数量：</span>
                        <input type="number" name="number[]" value="" class="span2 btn btn-default btn-xs number"/>
                    </div>
                    <div class="input-prepend juli">
                        <span class="add-on btn btn-info btn-xs">单位：</span>
                        <select class="span2 btn btn-default btn-xs unit" name="unit[]">
                            <option value="0">----请选择----</option>
                            <option value="1">个/双</option>
                            <option value="2">袋/盒（多个）</option>
                        </select>
                    </div>
                    <input type="hidden" id="shu" value="1"/>
                </td>
            </tr>
            <tr id="last">
                <td style="text-align: center;">
                    <input type="checkbox" name="c_hot" checked value="1">
                    &nbsp;<span class="add-on btn btn-info btn-xs">热门</span>&nbsp;
                    <button type="button" class="btn btn-primary btn-lg" onclick="sub()">上传</button>
                </td>
            </tr>
        </table>
    </div>
</form>
<include file="Public:title_last"/>

<script type="text/javascript">
    function add() {
        var str = "";
        var obj = document.getElementById('shu');
        var value = obj.getAttribute('value');
        obj.setAttribute('value', Number(value) + 1)
        str += "<tr id='add" + Number(value) + "'>" +
                "<td>" +
                "<div class='input-prepend'>" +
                "<span class='add-on btn btn-info btn-xs'>方案添加：</span>" +
                "<input type='text' name='attribute[]' value='' class='span2 btn btn-default btn-xs taocan'/>" +
                "</div>" +
                "<div class='input-prepend juli'>" +
                "<span class='add-on btn btn-info btn-xs'>方案图片</span>" +
                "<input type='file' style='display: inline-block;' id='fa_img'" +
                "class='span2 btn btn-default btn-xs juli'" +
                "name='fa_img["+Number(value) +"][]'" +
                "multiple='multiple'/>" +
                "</div>" +
                "<div class='input-prepend juli'>" +
                "<span class='add-on btn btn-info btn-xs'>价格(进价)：</span>" +
                "<input type='number' name='price[]' value='' class='span2 btn btn-default btn-xs money'/>" +
                "</div>" +
                "<div class='input-prepend juli'>" +
                "<span class='add-on btn btn-info btn-xs'>上架数量：</span>" +
                "<input type='number' name='number[]' value='' class='span2 btn btn-default btn-xs number'/>" +
                "</div>" +
                "<div class='input-prepend juli'>" +
                "<span class='add-on btn btn-info btn-xs'>单位：</span>" +
                "<select class='span2 btn btn-default btn-xs unit' name='unit[]'>" +
                "<option value='0'>----请选择----</option>" +
                "<option value='1'>个/双</option>" +
                "<option value='2'>袋/盒（多个）</option>" +
                "</select>" +
                "</div>" +
                "<div class='input-prepend juli'>" +
                "<span class='add-on btn btn-info btn-xs'>删除：</span>" +
                "&nbsp;<button class='btn btn-default btn-lg' type='button' onclick ='remove(" + Number(value) + ")'>-</button>" +
                "</div>" +
                "</td>" +
                "</tr>";
        document.getElementById('last').insertAdjacentHTML('beforeBegin', str);
    }
    function remove(a) {
        var selectors = document.getElementById("add" + a + "");
        selectors.remove();
    }
    function sub() {
        var filelength = document.getElementById('file').value.length;
        var filelength2 = document.getElementById('fa_img').value.length;
        var number = document.getElementsByClassName('number');
        var taocan = document.getElementsByClassName('taocan');
        var money = document.getElementsByClassName('money');
        var select = document.getElementById('select');

        var title_m = document.getElementById('title_m');
        var num_m = document.getElementById('num_m');
        var unit = document.getElementsByClassName('unit');
        var price_m = document.getElementById('price_m');
        var t = 1;
        var m = 1;
        var n = 1;
        var t_m = 1;
        var n_m = 1;
        var u_m = 1;
        var p_m = 1;
        for (var a = 0; a < taocan.length; a++) {
            if (!taocan[a].value) {
                t = 0;
            }
        }
        for (var b = 0; b < money.length; b++) {
            if (!money[b].value) {
                m = 0;
            }
        }
        for (var c = 0; c < number.length; c++) {
            if (!number[c].value) {
                n = 0;
            }
        }
        for (var d = 0; d < unit.length; d++) {
            if (unit[d].value==0) {
                u_m = 0;
            }
        }
        //----
        if (!title_m.value) {
            t_m = 0;
        }

        if (!num_m.value) {
            n_m = 0;
        }
        if (!price_m.value) {
            p_m = 0;
        }
//console.log(u_m);
        if (select.value == 0) {
            alert('商品类别未选择！！！')
        }
        if (filelength != 0 && filelength2 != 0 && t == 1 && m == 1 && n == 1 && t_m == 1 && n_m == 1 && u_m == 1 && p_m == 1 && select.value != 0) {
            document.getElementsByClassName('form')[0].submit();
//            document.getElementById('form').submit();
        } else {
            alert('有漏填选项！！！')
        }
    }
    function reback() {
        window.location.href = "show.html";
    }
</script>
</html>
